package com.example.rdcproject.ving.notes.util;

import javax.swing.*;
import java.util.regex.Pattern;

public class NumberInputVerifier extends InputVerifier {

    private final Pattern pattern = Pattern.compile("\\d+");

    @Override
    public boolean verify(JComponent input) {
        JTextField textField = (JTextField) input;
        String text = textField.getText().trim();
        if (pattern.matcher(text).matches()) {
            return true;
        } else {
            JOptionPane.showMessageDialog(null, "请输入数字！", "错误", JOptionPane.ERROR_MESSAGE);
            textField.setText("");
            return false;
        }
    }
}

